package com.example.qianfeng.proxy;

public class StaticProxy {
    public static void main(String[] args) {
        UserAction userAction = new UserAction();
        ProxyAction proxyAction = new ProxyAction(userAction);
        proxyAction.doAction();
    }
}

// 定义一个接口
interface Action {
    void doAction();
}


/**
 * 实现类实现接口重写方法
 */
class UserAction implements Action {

    @Override
    public void doAction() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("execute user's code====");
        }
    }
}

/**
 * 代理类实现接口
 */
class ProxyAction implements Action {

    // 获取接口的实例
    private Action target;

    public ProxyAction(Action target) {
        this.target = target;
    }

    @Override
    public void doAction() {
        long startTime = System.currentTimeMillis();
        target.doAction();
        long endTime = System.currentTimeMillis();
        System.out.println("一共耗时：" + (endTime - startTime));
    }
}